﻿using RRKAutohaus.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RRKAutohaus.Core.Repositories
{
    public class CarRepository: Repository<Car>, ICarRepository
    {

        public CarRepository(DbContext dbContext)
            : base(dbContext){}

        public new IQueryable<Car> GetAll()
        {
            var cars = dbSet.Include(c => c.Image)
                            .Where(c => c.Status == "A")
                            .OrderByDescending(c => c.DatePosted);

            return cars;
        }

        public IQueryable<Car> GetCarsByMonth(DateTime month)
        {
            var cars = dbSet.Include(c => c.Image)
                            .OrderByDescending(c => c.DatePosted)
                            .Take(18);
            return cars;

            //fake data
            //var cars = dbSet.Include(c => c.Image).OrderByDescending(c => c.DatePosted).Take(5).ToList();
            //var car = cars.First();
            //for (int i = 0; i < 111; i++)
            //{
            //    cars.Add(car);
            //}
            //IEnumerable<Car> fakeCars = cars;

            //return fakeCars.AsQueryable();
        }


        public IQueryable<Car> GetFeaturedCars()
        {

            var cars = dbSet.Include(c => c.Image)
                            .OrderBy(c => c.DatePosted)
                            .Where(c => c.IsFeatured == true);
            return cars;
           
        }
    }
}
